﻿<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../Brushes.xaml"/>
  </ResourceDictionary.MergedDictionaries>

  <!-- Style TargetType="{x:Type Menu}">
    <!-  BasedOn="{StaticResource {x:Type Menu}" ->
    <Setter Property="Background" Value="{StaticResource MenuBackground}" />
  </Style -->

  <!-- Source: http://msdn.microsoft.com/de-de/library/ms747082%28v=vs.85%29.aspx -->
  <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="Separator">
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="Height" Value="1"/>
    <Setter Property="Margin" Value="36,3,9,3"/>
    <Setter Property="Focusable" Value="false" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="Separator">
          <Border BorderBrush="{StaticResource HeaderSeparatorBrush}" BorderThickness="1"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type Menu}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Foreground" Value="{StaticResource MenuTextBrush}"/>
    <Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Menu}">
          <Grid>
            <Border x:Name="Border" Background="{StaticResource MenuBarBackgroundBrush}"
                                    BorderBrush="{StaticResource MenuBarBackgroundBorderBrush}" BorderThickness="1">
              <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
            </Border>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Background" Value="{StaticResource DisabledMenuBarBackgroundBrush}" TargetName="Border"/>
              <Setter Property="BorderBrush" Value="{StaticResource DisabledMenuBarBorderBrush}" TargetName="Border"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <DropShadowBitmapEffect x:Key="PopupDropShadow" ShadowDepth="3" Softness="0.25" Opacity="0.3" Color="White" />
  <Style TargetType="{x:Type MenuItem}">
    <Style.Resources>
      <Geometry x:Key="Checkmark">M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z</Geometry>

      <Style x:Key="MenuScrollButton" BasedOn="{x:Null}" TargetType="{x:Type RepeatButton}">
        <Setter Property="ClickMode" Value="Hover" />
        <Setter Property="MinWidth" Value="0" />
        <Setter Property="MinHeight" Value="0" />
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type RepeatButton}">
              <DockPanel SnapsToDevicePixels="true" Background="Transparent">
                <Rectangle Fill="Transparent" x:Name="R1" Width="1" DockPanel.Dock="Right" />
                <Rectangle Fill="Transparent" x:Name="B1" Height="1" DockPanel.Dock="Bottom" />
                <Rectangle Fill="Transparent" x:Name="L1" Width="1" DockPanel.Dock="Left" />
                <Rectangle Fill="Transparent" x:Name="T1" Height="1" DockPanel.Dock="Top" />
                <ContentPresenter HorizontalAlignment="Center" Margin="2,2,2,2" x:Name="ContentContainer" VerticalAlignment="Center" />
              </DockPanel>
              <ControlTemplate.Triggers>
                <Trigger Property="IsPressed" Value="true">
                  <Setter Property="Fill" TargetName="R1" Value="{StaticResource FocusScrollButtonBrush}" />
                  <Setter Property="Fill" TargetName="B1" Value="{StaticResource FocusScrollButtonBrush}" />
                  <Setter Property="Fill" TargetName="L1" Value="{StaticResource FocusScrollButtonBrush}" />
                  <Setter Property="Fill" TargetName="T1" Value="{StaticResource FocusScrollButtonBrush}" />
                  <Setter Property="Margin" TargetName="ContentContainer" Value="3,3,1,1" />
                </Trigger>
              </ControlTemplate.Triggers>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
      <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry>
      <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />
      <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry>
      <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry>

      <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}" BasedOn="{x:Null}" TargetType="{x:Type ScrollViewer}">
        <Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
        <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollViewer}">
              <Grid SnapsToDevicePixels="true">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Border Grid.Row="1">
                  <ScrollContentPresenter Margin="{TemplateBinding Padding}" />
                </Border>
                <RepeatButton Style="{StaticResource MenuScrollButton}"
                              Focusable="false" Command="{x:Static ScrollBar.LineUpCommand}"
                              CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                  <RepeatButton.Visibility>
                    <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="0">
                      <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                    </MultiBinding>
                  </RepeatButton.Visibility>
                  <Path Fill="{StaticResource ScrollButtonBrush}" Data="{StaticResource UpArrow}" />
                </RepeatButton>
                <RepeatButton Style="{StaticResource MenuScrollButton}" Focusable="false" Grid.Row="2" Command="{x:Static ScrollBar.LineDownCommand}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                  <RepeatButton.Visibility>
                    <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="100">
                      <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                    </MultiBinding>
                  </RepeatButton.Visibility>
                  <Path Fill="{StaticResource ScrollButtonBrush}" Data="{StaticResource DownArrow}" />
                </RepeatButton>
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>

      <!-- Style the area of each sub-menu in which items are placed -->
      <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}"
                       TargetType="{x:Type ContentControl}">
        <Border Background="{StaticResource MenuBackground}"
                BorderBrush="{StaticResource MenuBorderBrush}"
                BorderThickness="1"
                CornerRadius="0,0,6,0">
          <Grid>
            <ContentPresenter Margin="1,0" Grid.ColumnSpan="2" />
          </Grid>
        </Border>
      </ControlTemplate>

      <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
        <!-- ControlTemplate.Resources>
          <Storyboard x:Key="HighlightOn">
            <DoubleAnimation Duration="00:00:00.1000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0.84"/>
          </Storyboard>
          <Storyboard x:Key="HighlightOff">
            <DoubleAnimation Duration="00:00:00.4000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0"/>
          </Storyboard>
        </ControlTemplate.Resources -->

        <Grid SnapsToDevicePixels="true">
          <Grid.RowDefinitions>
            <RowDefinition Height="*" />
          </Grid.RowDefinitions>
          <Rectangle x:Name="BackgroundGradientOver" Fill="{StaticResource hoverGradient}" Stroke="{StaticResource hoverStroke}" RadiusX="2" RadiusY="2"  Opacity="0" Grid.ColumnSpan="4"/>
          <Rectangle x:Name="BackgroundGradientSelected" Fill="{StaticResource BtnOverFill}" Stroke="{StaticResource selectedStroke}" RadiusX="2" RadiusY="2" Opacity="0" Grid.ColumnSpan="4"/>

          <Grid VerticalAlignment="Center">
            <Grid.ColumnDefinitions>
              <ColumnDefinition SharedSizeGroup="MenuItemIconColumnGroup" MinWidth="36" Width="Auto" />
              <ColumnDefinition Width="4" />
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="37" />
              <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto" />
              <ColumnDefinition Width="17" />
            </Grid.ColumnDefinitions>

            <ContentPresenter Margin="0,0,2,0" x:Name="Icon"
                              VerticalAlignment="Center"
                              HorizontalAlignment="Center"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Icon" />

            <Border Margin="-2,0,0,0" x:Name="GlyphPanel"
                    Width="22" Height="22"
                    Visibility="Hidden"
                    HorizontalAlignment="Center"
                    Background="{StaticResource CheckMarkBackgroundBrush}"
                    BorderBrush="{StaticResource CheckMarkBorderBrush}"
                    BorderThickness="1" CornerRadius="3">

              <Path Fill="{StaticResource CheckMarkForegroundBrush}"
                    HorizontalAlignment="Center"
                    FlowDirection="LeftToRight" x:Name="Glyph" Width="9" Height="11" Data="{StaticResource Checkmark}" />
            </Border>
            <ContentPresenter Margin="{TemplateBinding Padding}"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                              Grid.Column="2"
                              ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
            <TextBlock Margin="{TemplateBinding Padding}" Grid.Column="4" Foreground="{StaticResource MenuTextBrush}" Text="{TemplateBinding InputGestureText}" />
          </Grid>
        </Grid>
        <ControlTemplate.Triggers>

          <!-- Trigger Property="IsPressed" Value="True">
            <Trigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </Trigger.ExitActions>
            <Trigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </Trigger.EnterActions>
          </Trigger -->
          <Trigger Property="Icon" Value="{x:Null}">
            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
          </Trigger>
          <Trigger Property="IsChecked" Value="true">
            <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
          </Trigger>
          <!-- Trigger Property="IsHighlighted" Value="true">
            <Trigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </Trigger.ExitActions>
            <Trigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </Trigger.EnterActions>
          </Trigger -->
          <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Foreground" Value="{StaticResource DisabledSubMenuItemForegroundBrush}" />
            <Setter Property="Background" TargetName="GlyphPanel" Value="{StaticResource DisabledSubMenuItemBackgroundBrush}" />
            <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="{StaticResource DisabledSubMenuItemBorderBrush}" />
            <Setter Property="Fill" TargetName="Glyph" Value="{StaticResource DisabledSubMenuItemFillBrush}" />
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>

      <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
        <!-- ControlTemplate.Resources>
          <Storyboard x:Key="HighlightOn">
            <DoubleAnimation Duration="00:00:00.1000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0.84"/>
          </Storyboard>
          <Storyboard x:Key="HighlightOff">
            <DoubleAnimation Duration="00:00:00.4000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0"/>
          </Storyboard>
        </ControlTemplate.Resources -->

        <Grid SnapsToDevicePixels="true">
          <Rectangle x:Name="BackgroundGradientOver" Fill="{StaticResource hoverGradient}" Stroke="{StaticResource hoverStroke}" RadiusX="2" RadiusY="2"  Opacity="0" Grid.ColumnSpan="4"/>
          <Rectangle x:Name="BackgroundGradientSelected" Fill="{StaticResource BtnOverFill}" Stroke="{StaticResource selectedStroke}" RadiusX="2" RadiusY="2" Opacity="0" Grid.ColumnSpan="4"/>

          <DockPanel>
            <ContentPresenter Margin="0,0,2,0" x:Name="Icon"
                              VerticalAlignment="Center"
                              HorizontalAlignment="Center"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Icon" />

            <Path Fill="{TemplateBinding Foreground}"
                  HorizontalAlignment="Center"
                  FlowDirection="LeftToRight" Margin="0,0,0,0" x:Name="GlyphPanel" VerticalAlignment="Center" Visibility="Collapsed" Data="{StaticResource Checkmark}" />
            <ContentPresenter Margin="{TemplateBinding Padding}"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                              ContentSource="Header"
                              RecognizesAccessKey="True" />
          </DockPanel>

          <!-- Style Pop-Menu entries directly under Main Menu Bar -->
          <Popup x:Name="PART_Popup" AllowsTransparency="true" HorizontalOffset="1" IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" VerticalOffset="-1" Focusable="false">
            <Grid x:Name="SubMenu">
              <Border x:Name="Shdw" CornerRadius="0,0,6,0">
                <ContentControl x:Name="SubMenuBorder"
                                  IsTabStop="false"
                                  Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                  <ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true">
                    <Grid>
                      <!-- Display nice icon column enhancement (even if there is no icon to be displayed) -->
                      <Border Margin="0,0,0,0" Width="36" Background="{StaticResource MenuDecorationBarGradient}" HorizontalAlignment="Left" />
                      <ItemsPresenter Margin="2"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                      Grid.IsSharedSizeScope="true"
                                      KeyboardNavigation.DirectionalNavigation="Cycle"
                                      KeyboardNavigation.TabNavigation="Cycle" />
                    </Grid>
                  </ScrollViewer>
                </ContentControl>
              </Border>
            </Grid>
          </Popup>
        </Grid>
        <ControlTemplate.Triggers>

          <!-- MultiTrigger>
            <MultiTrigger.Conditions>
              <Condition Property="IsChecked" Value="True"/>
              <Condition Property="IsHighlighted" Value="True"/>
            </MultiTrigger.Conditions>
            <MultiTrigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </MultiTrigger.ExitActions>
            <MultiTrigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </MultiTrigger.EnterActions>
          </MultiTrigger -->

          <Trigger Property="IsSuspendingPopupAnimation" Value="true">
            <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None" />
          </Trigger>
          <Trigger Property="Icon" Value="{x:Null}">
            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
          </Trigger>
          <Trigger Property="IsChecked" Value="true">
            <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
          </Trigger>

          <Trigger Property="AllowsTransparency" SourceName="PART_Popup" Value="true">
            <Setter Property="Margin" Value="0,0,3,3" TargetName="SubMenu"/>
            <Setter Property="SnapsToDevicePixels" Value="true" TargetName="SubMenu"/>
            <Setter Property="BitmapEffect" Value="{DynamicResource PopupDropShadow}" TargetName="Shdw"/>
          </Trigger>

          <!-- Trigger Property="IsHighlighted" Value="true">
            <Trigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </Trigger.ExitActions>
            <Trigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </Trigger.EnterActions>
          </Trigger -->
          <!-- Trigger Property="IsKeyboardFocused" Value="true">
            <Trigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </Trigger.ExitActions>
            <Trigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </Trigger.EnterActions>
          </Trigger>
          <Trigger Property="IsSubmenuOpen" Value="true">
            <Trigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </Trigger.ExitActions>
            <Trigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </Trigger.EnterActions>
          </Trigger -->
          <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Foreground" Value="{StaticResource DisabledMenuItemForegroundBrush}" />
            <Setter Property="Fill" TargetName="GlyphPanel" Value="{StaticResource DisabledMenuItemFillBrush}" />
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>

      <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
        <!-- ControlTemplate.Resources>
          <Storyboard x:Key="HighlightOn">
            <DoubleAnimation Duration="00:00:00.1000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0.84"/>
          </Storyboard>
          <Storyboard x:Key="HighlightOff">
            <DoubleAnimation Duration="00:00:00.4000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0"/>
          </Storyboard>
        </ControlTemplate.Resources -->

        <Grid SnapsToDevicePixels="true">

          <Rectangle x:Name="BackgroundGradientOver" Fill="{StaticResource hoverGradient}" Stroke="{StaticResource hoverStroke}" RadiusX="2" RadiusY="2"  Opacity="0" Grid.ColumnSpan="4"/>
          <Rectangle x:Name="BackgroundGradientSelected" Fill="{StaticResource BtnOverFill}" Stroke="{StaticResource selectedStroke}" RadiusX="2" RadiusY="2" Opacity="0" Grid.ColumnSpan="4"/>

          <Rectangle Margin="2" x:Name="InnerBorder" />
          <DockPanel>
            <ContentPresenter Margin="0,0,2,0" x:Name="Icon"
                              VerticalAlignment="Center"
                              HorizontalAlignment="Center"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Icon" />

            <Path Fill="{TemplateBinding Foreground}"
                  HorizontalAlignment="Center"
                  FlowDirection="LeftToRight" VerticalAlignment="Center" Margin="0,0,0,0" x:Name="GlyphPanel" Visibility="Collapsed" Data="{StaticResource Checkmark}" />

            <ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" RecognizesAccessKey="True" />
          </DockPanel>
        </Grid>
        <ControlTemplate.Triggers>
          <Trigger Property="Icon" Value="{x:Null}">
            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
          </Trigger>
          <Trigger Property="IsChecked" Value="true">
            <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
          </Trigger>
          <!-- Trigger Property="IsHighlighted" Value="true">
            <Trigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </Trigger.ExitActions>
            <Trigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </Trigger.EnterActions>
            <Setter Property="Stroke" TargetName="InnerBorder" Value="{StaticResource TopLevelIsHighlightedInnerBorderStroke}" />
          </Trigger -->
          <!-- Trigger Property="IsKeyboardFocused" Value="true">
            <Setter Property="Stroke" TargetName="InnerBorder" Value="{StaticResource TopLevelIsKeyboardFocusedInnerBorderStroke}" />
            <Trigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </Trigger.ExitActions>
            <Trigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </Trigger.EnterActions>
          </Trigger -->
          <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Foreground" Value="{StaticResource DisabledMenuItemForegroundBrush}" />
            <Setter Property="Fill" TargetName="GlyphPanel" Value="{StaticResource DisabledMenuItemFillBrush}" />
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>

      <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
        <!-- ControlTemplate.Resources>
          <Storyboard x:Key="HighlightOn">
            <DoubleAnimation Duration="00:00:00.1000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0.84"/>
          </Storyboard>
          <Storyboard x:Key="HighlightOff">
            <DoubleAnimation Duration="00:00:00.4000000" Storyboard.TargetName="BackgroundGradientSelected" Storyboard.TargetProperty="Opacity" To="0"/>
          </Storyboard>
        </ControlTemplate.Resources -->

        <Grid SnapsToDevicePixels="true">

          <Rectangle x:Name="BackgroundGradientOver" Fill="{StaticResource hoverGradient}" Stroke="{StaticResource hoverStroke}" RadiusX="2" RadiusY="2"  Opacity="0" Grid.ColumnSpan="4"/>
          <Rectangle x:Name="BackgroundGradientSelected" Fill="{StaticResource BtnOverFill}" Stroke="{StaticResource selectedStroke}" RadiusX="2" RadiusY="2" Opacity="0" Grid.ColumnSpan="4"/>

          <Grid SnapsToDevicePixels="True">
            <Grid.ColumnDefinitions>
              <ColumnDefinition SharedSizeGroup="MenuItemIconColumnGroup" MinWidth="36" Width="Auto" />
              <ColumnDefinition Width="4" />
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="37" />
              <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto" />
              <ColumnDefinition Width="17" />
            </Grid.ColumnDefinitions>
            <ContentPresenter Margin="0,0,2,0" x:Name="Icon" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Icon" />
            <Border Margin="-2,0,0,0" x:Name="GlyphPanel"
                    Width="22" Height="22"
                    VerticalAlignment="Center"
                    Visibility="Hidden"
                    Background="{StaticResource CheckMarkBackgroundBrush}"
                    BorderBrush="{StaticResource CheckMarkBorderBrush}"
                    BorderThickness="1" CornerRadius="3">
              <Path Fill="{StaticResource CheckMarkForegroundBrush}"
                    VerticalAlignment="Center"
                    FlowDirection="LeftToRight" x:Name="Glyph" Width="9" Height="11" Data="{StaticResource Checkmark}" />
            </Border>

            <ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.Column="2" ContentSource="Header" RecognizesAccessKey="True" />

            <TextBlock Margin="{TemplateBinding Padding}" Visibility="Collapsed" Grid.Column="4" Text="{TemplateBinding InputGestureText}" />

            <Path Fill="{StaticResource ScrollButtonBrush}" Margin="4,0,0,0" VerticalAlignment="Center" Grid.Column="5" Data="{StaticResource RightArrow}" />
          </Grid>

          <!-- Style a sub-menu popup-menu entry (a pop-menu under a menu item with right arrow) -->
          <Popup x:Name="PART_Popup" AllowsTransparency="true"
                                     HorizontalOffset="-2"
                                     IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
                                     Placement="Right" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                                     VerticalOffset="-3"
                                     Focusable="false">
            <Grid x:Name="SubMenu">
              <Border x:Name="Shdw" Background="{x:Null}" CornerRadius="0,0,6,0">
                <ContentControl x:Name="SubMenuBorder" IsTabStop="false" Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                  <ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true">
                    <Grid>
                      <!-- Display nice icon column enhancement (even if there is no icon to be displayed) -->
                      <Border Margin="0,0,0,0" Width="36" Background="{StaticResource MenuDecorationBarGradient}" HorizontalAlignment="Left" />
                      <ItemsPresenter Margin="2"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                    Grid.IsSharedSizeScope="true"
                                    KeyboardNavigation.DirectionalNavigation="Cycle"
                                    KeyboardNavigation.TabNavigation="Cycle" />
                    </Grid>
                  </ScrollViewer>
                </ContentControl>
              </Border>
            </Grid>
          </Popup>
        </Grid>

        <ControlTemplate.Triggers>
          <!-- Trigger Property="IsPressed" Value="True">
            <Trigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </Trigger.ExitActions>
            <Trigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </Trigger.EnterActions>
          </Trigger -->

          <Trigger Property="IsSuspendingPopupAnimation" Value="true">
            <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None" />
          </Trigger>

          <Trigger Property="Icon" Value="{x:Null}">
            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
          </Trigger>

          <Trigger Property="IsChecked" Value="true">
            <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
            <Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
          </Trigger>

          <Trigger Property="AllowsTransparency" SourceName="PART_Popup" Value="true">
            <Setter Property="Margin" Value="0,0,3,3" TargetName="SubMenu"/>
            <Setter Property="SnapsToDevicePixels" Value="true" TargetName="SubMenu"/>
            <Setter Property="BitmapEffect" Value="{DynamicResource PopupDropShadow}" TargetName="Shdw"/>
          </Trigger>

          <!-- Trigger Property="IsHighlighted" Value="true">
            <Trigger.ExitActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOff}" />
            </Trigger.ExitActions>
            <Trigger.EnterActions>
              <BeginStoryboard Storyboard="{StaticResource HighlightOn}" />
            </Trigger.EnterActions>
          </Trigger -->

          <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Foreground" Value="{StaticResource DisabledSubMenuItemForegroundBrush}" />
            <Setter Property="Background" TargetName="GlyphPanel" Value="{StaticResource DisabledSubMenuItemBackgroundBrush}" />
            <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="{StaticResource DisabledSubMenuItemBorderBrush}" />
            <Setter Property="Fill" TargetName="Glyph" Value="{StaticResource DisabledSubMenuItemFillBrush}" />
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>

    </Style.Resources>

    <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
    <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="Foreground" Value="{StaticResource MenuTextBrush}"/>
    <Style.Triggers>
      <!-- Style an entry that is visible at the top-level of a main menu in the menu bar -->
      <Trigger Property="Role" Value="TopLevelHeader">
        <Setter Property="Padding" Value="7,2,8,3" />
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
      </Trigger>

      <Trigger Property="Role" Value="TopLevelItem">
        <Setter Property="Padding" Value="7,2,8,3" />
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
      </Trigger>

      <!-- Style a menu item that has a sub-menu (entry with right arrow) attached to it -->
      <Trigger Property="Role" Value="SubmenuHeader">
        <Setter Property="Padding" Value="2,3,2,3" />
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
      </Trigger>

      <!-- Style the entries in a sub-menu (below an entry with right arrow) -->
      <Trigger Property="Role" Value="SubmenuItem">
        <Setter Property="Padding" Value="2,3,2,3" />
      </Trigger>
    </Style.Triggers>
  </Style>

  <!-- CONTEXT MENU XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->
  <Style TargetType="{x:Type ContextMenu}">
    <Style.Resources>
      <Style x:Key="MenuScrollButton" BasedOn="{x:Null}" TargetType="{x:Type RepeatButton}">
        <Setter Property="ClickMode" Value="Hover" />
        <Setter Property="MinWidth" Value="0" />
        <Setter Property="MinHeight" Value="0" />
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type RepeatButton}">
              <DockPanel SnapsToDevicePixels="true" Background="Transparent">
                <Rectangle Fill="Transparent" x:Name="R1" Width="1" DockPanel.Dock="Right" />
                <Rectangle Fill="Transparent" x:Name="B1" Height="1" DockPanel.Dock="Bottom" />
                <Rectangle Fill="Transparent" x:Name="L1" Width="1" DockPanel.Dock="Left" />
                <Rectangle Fill="Transparent" x:Name="T1" Height="1" DockPanel.Dock="Top" />
                <ContentPresenter HorizontalAlignment="Center" Margin="2,2,2,2" x:Name="ContentContainer" VerticalAlignment="Center" />
              </DockPanel>
              <ControlTemplate.Triggers>
                <Trigger Property="IsPressed" Value="true">
                  <Setter Property="Fill" TargetName="R1" Value="{StaticResource FocusScrollButtonBrush}" />
                  <Setter Property="Fill" TargetName="B1" Value="{StaticResource FocusScrollButtonBrush}" />
                  <Setter Property="Fill" TargetName="L1" Value="{StaticResource FocusScrollButtonBrush}" />
                  <Setter Property="Fill" TargetName="T1" Value="{StaticResource FocusScrollButtonBrush}" />
                  <Setter Property="Margin" TargetName="ContentContainer" Value="3,3,1,1" />
                </Trigger>
              </ControlTemplate.Triggers>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
      <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry>
      <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />
      <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry>
      <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry>

      <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}" BasedOn="{x:Null}" TargetType="{x:Type ScrollViewer}">
        <Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
        <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollViewer}">
              <Grid SnapsToDevicePixels="true">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="*" />
                  <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Border Grid.Row="1">
                  <ScrollContentPresenter Margin="{TemplateBinding Padding}" />
                </Border>
                <RepeatButton Style="{StaticResource MenuScrollButton}"
                              Focusable="false" Command="{x:Static ScrollBar.LineUpCommand}"
                              CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                  <RepeatButton.Visibility>
                    <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="0">
                      <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                    </MultiBinding>
                  </RepeatButton.Visibility>
                  <Path Fill="{StaticResource ScrollButtonBrush}" Data="{StaticResource UpArrow}" />
                </RepeatButton>
                <RepeatButton Style="{StaticResource MenuScrollButton}" Focusable="false" Grid.Row="2" Command="{x:Static ScrollBar.LineDownCommand}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                  <RepeatButton.Visibility>
                    <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="100">
                      <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                      <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}" />
                    </MultiBinding>
                  </RepeatButton.Visibility>
                  <Path Fill="{StaticResource ScrollButtonBrush}" Data="{StaticResource DownArrow}" />
                </RepeatButton>
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>

      <!-- Style the area of each sub-menu in which items are placed -->
      <ControlTemplate x:Key="{ComponentResourceKey ResourceId=ContextmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}" TargetType="{x:Type ContentControl}">
        <Border Background="{StaticResource MenuBackground}"
                BorderBrush="{StaticResource MenuBorderBrush}"
                BorderThickness="1"
                CornerRadius="0,0,6,0">
          <Grid>
            <ContentPresenter Margin="1,0" Grid.ColumnSpan="2" />
          </Grid>
        </Border>
      </ControlTemplate>
    </Style.Resources>

    <!-- Setter Property="Background" Value="{DynamicResource MenuBackgroundBrush}"/ -->
    <!-- Setter Property="BorderThickness" Value="1"/ -->
    <!-- Setter Property="BorderBrush" Value="{DynamicResource WindowBorderBrush}"/ -->
    <Setter Property="HasDropShadow" Value="True" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ContextMenu}">
          <!-- Style ContextMenu such that Drop shadow is visible through Grid with Margin 0,0,3,3 -->
          <Grid x:Name="SubMenu" Margin="0,0,3,3" SnapsToDevicePixels="true">
            <!-- Implement drop shadow through border with bitmap effect -->
            <Border x:Name="Shdw"
                      Background="{StaticResource MenuBackground}"
                      CornerRadius="0,0,6,0"
                      BorderBrush="Transparent"
                      BorderThickness="0"
                      BitmapEffect="{DynamicResource PopupDropShadow}">
              <Grid Margin="0">
                <ContentControl x:Name="SubMenuBorder"
                                    IsTabStop="false"
                                    Template="{DynamicResource {ComponentResourceKey ResourceId=ContextmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
                  <ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"
                                    CanContentScroll="true">
                    <Grid>
                      <!-- Display nice icon column enhancement (even if there is no icon to be displayed) -->
                      <Border Margin="0,0,0,0" Width="36" Background="{StaticResource MenuDecorationBarGradient}" HorizontalAlignment="Left" VerticalAlignment="Stretch" />
                      <ItemsPresenter Margin="2"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                            Grid.IsSharedSizeScope="true"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"
                                            KeyboardNavigation.TabNavigation="Cycle" />
                    </Grid>
                  </ScrollViewer>
                </ContentControl>
              </Grid>
            </Border>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>
